package com.huiyujinrong.qiangdanbao.activity.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huiyujinrong.qiangdanbao.R;
import com.huiyujinrong.qiangdanbao.adapter.FindAdapter;
import com.huiyujinrong.qiangdanbao.adapter.SportAdapter;
import com.huiyujinrong.qiangdanbao.bean.SportItemBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FragmentFound extends Fragment {

    @BindView(R.id.toolbar_Title)
    TextView toolbar_title;

    @BindView(R.id.RecyclerView)
    RecyclerView recyclerView;

    @BindView(R.id.RecyclerView2)
    RecyclerView recyclerView2;
    FindAdapter adapter;


    List<String> data = new ArrayList<>();

    SportAdapter activityAdapter;
    List<Object> activity = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_found, container, false);
        ButterKnife.bind(this, v);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator()); // 默认动画
        adapter = new FindAdapter(getActivity(), data);
        recyclerView.setAdapter(adapter);
        adapter.setmItemClickListener(new FindAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View v) {//跳转展业神器
                startActivity(new Intent(getActivity(),ExhibitionEditActivity.class));
            }
        });

        recyclerView2.setHasFixedSize(true);
        recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView2.setItemAnimator(new DefaultItemAnimator()); // 默认动画
        activityAdapter = new SportAdapter(getActivity(), activity);
        recyclerView2.setAdapter(activityAdapter);
        activityAdapter.setmItemClickListener(new SportAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View view) {

            }

            @Override
            public void onHeaderClickListener(View view) {

            }
        });
        initData();
        return v;
    }

    private void initData() {


        data.add("http://img2.imgtn.bdimg.com/it/u=2850936076,2080165544&fm=206&gp=0.jpg");
        data.add("http://img3.imgtn.bdimg.com/it/u=524208507,12616758&fm=206&gp=0.jpg");
        data.add("http://img3.imgtn.bdimg.com/it/u=698582197,4250615262&fm=206&gp=0.jpg");
        data.add("http://img5.imgtn.bdimg.com/it/u=1467751238,3257336851&fm=11&gp=0.jpg");
        data.add("http://img2.imgtn.bdimg.com/it/u=4081165325,36916497&fm=21&gp=0.jpg");
        data.add("http://img4.imgtn.bdimg.com/it/u=4141168524,78676102&fm=21&gp=0.jpg");
        data.add("http://img3.imgtn.bdimg.com/it/u=698582197,4250615262&fm=206&gp=0.jpg");
        data.add("http://img3.imgtn.bdimg.com/it/u=2566161363,1140447270&fm=206&gp=0.jpg");


        SportItemBean itemBean = new SportItemBean("http://img2.imgtn.bdimg.com/it/u=2850936076,2080165544&fm=206&gp=0.jpg", "我是标题0号，请给我0票");
        SportItemBean itemBean1 = new SportItemBean("http://img4.imgtn.bdimg.com/it/u=4141168524,78676102&fm=21&gp=0.jpg", "我是标题1号，请给我一票");
        SportItemBean itemBean2 = new SportItemBean("http://img3.imgtn.bdimg.com/it/u=524208507,12616758&fm=206&gp=0.jpg", "我是标题2号，请给我2票");
        SportItemBean itemBean3 = new SportItemBean("http://img5.imgtn.bdimg.com/it/u=1467751238,3257336851&fm=11&gp=0.jpg", "我是标题3号，请给我3票");
        SportItemBean itemBean4 = new SportItemBean("http://img3.imgtn.bdimg.com/it/u=698582197,4250615262&fm=206&gp=0.jpg", "我是标题4号，请给我4票");
        SportItemBean itemBean5 = new SportItemBean("http://img2.imgtn.bdimg.com/it/u=2850936076,2080165544&fm=206&gp=0.jpg", "我是标题5号，请给我5票");
        SportItemBean itemBean6 = new SportItemBean("http://img3.imgtn.bdimg.com/it/u=524208507,12616758&fm=206&gp=0.jpg", "我是标题6号，请给我6票");
        SportItemBean itemBean7 = new SportItemBean("http://img3.imgtn.bdimg.com/it/u=2566161363,1140447270&fm=206&gp=0.jpg", "我是标题7号，请给我7票");
        SportItemBean itemBean8 = new SportItemBean("http://img3.imgtn.bdimg.com/it/u=698582197,4250615262&fm=206&gp=0.jpg", "我是标题8号，请给我8票");
        SportItemBean itemBean9 = new SportItemBean("http://img3.imgtn.bdimg.com/it/u=698582197,4250615262&fm=206&gp=0.jpg", "我是标题8号，请给我8票");
        activity.add(itemBean);
        activity.add(itemBean1);
        activity.add(itemBean2);
        activity.add(itemBean3);
        activity.add(itemBean4);
        activity.add(itemBean5);
        activity.add(itemBean6);
        activity.add(itemBean7);
        activity.add(itemBean8);
        activity.add(itemBean9);
        adapter.notifyDataSetChanged();
        activityAdapter.notifyDataSetChanged();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setToolbar();
    }


    private void setToolbar() {
        toolbar_title.setText("发现");
    }

    @OnClick({R.id.llExhibition, R.id.llActivity})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llExhibition:
                startActivity(new Intent(getActivity(), ExhibitionActivity.class));
                break;
            case R.id.llActivity:
                startActivity(new Intent(getActivity(), SplendidActivity.class));
                break;
        }
    }

}
